package com.lf.lexy.dao;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.lf.comm.MyConstants;
import com.lf.lexy.model.User;
import com.lf.lexy.webutils.CommMethod;
import com.lf.lexy.webutils.DateUtils;
import com.lf.lexy.webutils.GetWaterId;

public class UserDao extends User {
	
	public static UserDao me = new UserDao();
	public Logger log = MyConstants.log;
	public static String TabName = CommMethod.getTbaleName(User.class.getSimpleName());
	
	public User getUser(String userName, String userPwd ){
		String sql = "select * from "+ CommMethod.getTbaleName(User.class.getSimpleName()) +" where user_no =? and user_pwd =? ";
		System.out.println(sql);
		return dao.findFirst(sql, userName ,userPwd );
	}
	
	
	
	public User geetUser(String userNo , String userMail , String userPhone , String userPwd){
		String sql = "select * from "+ TabName +" where 1=1 and user_pwd = '"+userPwd+"'";
		sql += " and ( user_no ='"+userNo+"' or user_mail ='"+userMail+"' or  user_phone ='"+userPhone+"') ";
		log.info("===> Sql : "+ sql);
		return dao.findFirst(sql);
	}
	
	
	public boolean insertUser(String userNo , String userMail , String userName , String userPhone , String userPwd){
		User user = new User();
		user.setSerialId(GetWaterId.getWaterId());
		user.setUserNo(userNo);
		user.setUserMail(userMail);
		user.setUserPhone(userPhone);
		user.setUserName(userName);
		user.setUserPwd(userPwd);
		user.setIsDelete("0");
		user.setUpdateTime(DateUtils.getCurrDateTime());
		return user.save();
	}
}
